package tp.aspect.counter;

import java.lang.reflect.Field;

public class Util {

	public static Object getField(Object target, String fieldName) {
		try {
			Field field = target.getClass().getDeclaredField(fieldName);
			if (!(field.isAccessible()))
				field.setAccessible(true);
			return field.get(target);
		} catch (IllegalArgumentException e) {
			throw new RuntimeException(
					"Error al acceder al valor del campo actual: "
							+ target.getClass() + "." + fieldName, e);
		} catch (SecurityException e) {
			throw new RuntimeException(
					"Error al acceder al valor del campo actual: "
							+ target.getClass() + "." + fieldName, e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(
					"Error al acceder al valor del campo actual: "
							+ target.getClass() + "." + fieldName, e);
		} catch (NoSuchFieldException e) {
			throw new RuntimeException(
					"Error al acceder al valor del campo actual: "
							+ target.getClass() + "." + fieldName, e);
		}
	}
}
